package cn.tedu.ivos.dictoption.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.dict.mapper.DictMapper;
import cn.tedu.ivos.dict.pojo.dto.DictQuery;
import cn.tedu.ivos.dict.pojo.vo.DictVO;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionQuery;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionSaveParam;
import cn.tedu.ivos.dictoption.pojo.vo.DictOptionVO;
import cn.tedu.ivos.dictoption.service.DictOptionService;
import cn.tedu.ivos.dictoption.service.impl.DOServiceImpl;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "字典项管理")
@RequestMapping("/v1/dictoption/")
@Slf4j
public class DictOptionController {
    @Autowired
    DictOptionService service;
    @Operation(summary = "查询字典项")
    @GetMapping("select")
    @ApiOperationSupport(order = 10)
    public JsonResult selectDictOption(DictOptionQuery query){
        log.debug("query:{}",query);
        List<DictOptionVO> list = service.selectDO(query);
        return JsonResult.ok(list);
    }

    @Operation(summary = "保存字典项")
    @ApiOperationSupport(order = 20)
    @PostMapping("save")
    public JsonResult saveDictOption(@Validated DictOptionSaveParam dictOptionSaveParam){
        log.debug("保存字典项,参数={}",dictOptionSaveParam);
        service.saveDictOption(dictOptionSaveParam);
        return JsonResult.ok();
    }

    @Operation(summary = "")
    @ApiOperationSupport(order = 30)
    @PostMapping("delete/{id}")
    public JsonResult deleteDictOption(@PathVariable Long id){
        log.debug("id:{}",id);
        service.deleteOption(id);
        return JsonResult.ok();
    }
    @Operation(summary = "根据字典code查字典项业务")
    @ApiOperationSupport(order = 40)
    @GetMapping("select/{code}")
    public JsonResult selectDictOpByDictCode(@PathVariable String code){
        log.debug("查询字典项,参数={}",code);
        List<DictOptionVO> list =
                service.selectDictOptionByDictCode(code);
        return JsonResult.ok(list);
    }
}
